package com.power.dao.impl;

import com.power.dao.LoginDao;
import com.power.pojo.Users;
import com.power.utils.JdbcBuild;

import java.sql.SQLException;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * User: 朱雄
 * Date: 2020/10/03 8:21
 * Description:
 * Version: V1.0
 * @author 浪人
 */
public class LoginDaoImpl extends JdbcBuild implements LoginDao {
    @Override
    public List<Map<String,Object>> login(Users users) throws SQLException {
        String sql="select * from users where user_account=? and user_pwd=? and is_delete=1";
        Object[] params={users.getUser_account(),users.getUser_pwd()};
        List<Map<String,Object>> list=super.findAllForList(sql,params);
        return list;
    }

    @Override
    public List<Map<String,Object>> loginByStat(Users users) throws SQLException {
        String sql="select * from users where user_account=? and user_state=1";
        Object[] params={users.getUser_account()};
        List<Map<String,Object>> list=super.findAllForList(sql,params);
        return list;
    }

    @Override
    public List<Map<String, Object>> loginByIsDelete(Users users) throws SQLException {
        String sql="select * from users where user_account=? and is_delete=1";
        Object[] params={users.getUser_account()};
        List<Map<String,Object>> list=super.findAllForList(sql,params);
        return list;
    }

    @Override
    public void updateLatly(String user_account, Date date) throws SQLException {
        String sql="update users set lately_time=? where user_account=?";
        Object[] params={date,user_account};
        super.executeUpdate(sql,params);
    }

    @Override
    public List<Map<String, Object>> findByRole(Users users) throws SQLException {
        String sql="select * from role where role_id=(SELECT role_id FROM users  where user_account=?) and role_state=1;";
        Object[] params={users.getUser_account()};
        List<Map<String, Object>> list=super.findAllForList(sql,params);
        return list;
    }

    @Override
    public List<Map<String, Object>> loginByAll(Users users) throws SQLException {
        String sql="select users.*,role_name,permission_name from users,role,role_permission,permission where user_account=? and users.role_id=role_permission.role_id and role_permission.permission=permission.permission_id  and users.role_id=role.role_id ";
        Object[] params={users.getUser_account()};
        List<Map<String,Object>> list=super.findAllForList(sql,params);
        return list;

    }
}
